﻿@model User
@{
    ViewBag.Title = T("Account");
}

<ul class="path floatContainer">
    <li class="first">@ActionLinkLocalized("Main", "Index", "Home")</li>
</ul>
<h1>@ViewBag.Title</h1>
@Html.ValidationSummary("<h3>" + S("Please check the following errors:") + "</h3>", new Dictionary<string, object>
	{
		{"Email", S("Email format is invalid.")}
		,{"Website", S("Website url format is invalid.")}
		,{"Photo", S("Photo url format is invalid.")}
		,{"Username", S("Username is required.")}
	}, null)
@{Html.BeginForm(null, null, FormMethod.Post, new { @id = "accountForm" });}
<fieldset>
    <div class="formItem floatContainer">
		<label for="title">@T("Public name")</label>
		@Html.TextBox("userName", null, new { @class = "text" })
    </div>
    <div class="formItem floatContainer">
		<label for="birthDate">@T("Birthdate")</label>
        @Html.TextBox("birthDate", Model.BirthDate != null ? Model.BirthDate.Value.ToString("d") : null, new { @class = "text" })
	</div>
	<div class="formItem floatContainer" style="display: none;">
		<label for="timezone">@T("Timezone")</label>
        @Html.TextBox("timezone", null, new { @class = "text" })
    </div>
    <div class="formItem floatContainer">
        <label>@ActionLinkLocalized("Avatar", "EditAvatar", new { userId = Model.Id, redirect = Url.Action("Edit", "Users", new { id = Model.Id }) }, null)</label>
        @if (Model.AvatarId.HasValue)
        {
            string url = Url.HttpRouteUrl("ApiActionById", new { Controller = "Image", Action = "Get", id = Model.AvatarId });
            <div class="photo">@Html.Img(url, Model.UserName)</div>
        }
        else
        {
		    <div class="nophoto"><span></span></div>
        }
    </div>
	<div class="formItem floatContainer">
		<label for="website">@T("Website")</label>
        @Html.TextBox("website", null, new { @class = "text" })
	</div>
	@if (User.Provider == AuthenticationProvider.Membership)
    {
        <p class="button">
            <input type="button" class="button" value="@T("Change Password")" 
                onclick="window.location.href='@Url.Action("ChangePassword", "FormsAuthentication", new { returnUrl = this.Request.Url.PathAndQuery })';" />
        </p>
    }
</fieldset>
@if (User.ProviderInfo.AllowChangeEmail)
{
	<h2>@T("Email")</h2>
	<fieldset>
		<legend>@T("Your email will not be shared with anyone. We will not make a different use than detailed below.")</legend>
		<div class="formItem floatContainer">
			<label for="email">@T("Email address")</label>
			@Html.TextBox("email", null, new { @class = "text" })
		</div>
		<div class="formItem floatContainer">
			<div class="checkbox" style="padding-top: 10px;">
				@(Html.CheckBoxBit<EmailPolicy>("policy1", Model.EmailPolicy, EmailPolicy.SendFromSubscriptions))
				<label for="policy1">@T("Use my email to notify me of replies to threads I subscribed to")</label>
			</div>
			<div class="checkbox" style="padding-top: 10px;">
				@(Html.CheckBoxBit<EmailPolicy>("policy2", Model.EmailPolicy, EmailPolicy.SendNewsletter))
				<label for="policy3">@T("Send me a newsletter")</label>
				@Html.Hidden("emailPolicy")
			</div>
		</div>
	</fieldset>
}
<div class="formItem buttons">
	<input type="submit" value="@T("Submit")" />
</div>
@{Html.EndForm();}

@if (!String.IsNullOrEmpty(User.ProviderInfo.EditAccountUrl))
{
	<p class="action"><a href="@User.ProviderInfo.EditAccountUrl">@T("To edit your account settings, click here")</a></p>
}
<script type="text/javascript">
    $(document).ready(function () {
        $("#accountForm").submit(function () {
            calculateEmailPolicy();
        });
    });

    function calculateEmailPolicy() {
        var value = 0;
        $("input:checked", $("#emailPolicy").parents("div.formItem")).each(function () {
            value += parseInt($(this).val(), 10);
        });
        $("#emailPolicy").val(value);
    }
</script>
